package com.controller;

import com.common.core.controller.BaseController;
import com.common.core.domain.AjaxResult;
import com.common.core.page.PageDomain;
import com.common.core.page.TableDataInfo;
import com.common.utils.CurrentRoleUtils;
import com.common.utils.SecurityUtils;
import com.domain.entity.AllName;
import com.domain.entity.BizFileShare;
import com.domain.entity.BusinessCount;
import com.research.domain.entity.ResearchUnit;
import com.research.service.IResearchUnitService;
import com.service.IFileSharedService;
import com.service.IHomePageService;
import com.system.domain.SysNotice;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 首页
 *
 * @author ruoyi
 */
@Api(tags ="首页")
@RestController
@RequestMapping("/homePage")
public class HomePageController extends BaseController {
    @Autowired
    private IHomePageService homePageService;

    @Autowired
    private IFileSharedService fileSharedService;

    /**科研平台*/
    @Autowired
    private IResearchUnitService researchUnitService;


    @ApiOperation("获取通知公告")
    @PostMapping("/noticeList")
    public TableDataInfo noticeList(@RequestBody SysNotice notice) {
        startPage();
        List<SysNotice> list = homePageService.getNoticeList(notice);
        return getDataTable(list);
    }

    @ApiOperation("待办事项")
    @PostMapping("/needTodoList")
    public TableDataInfo needTodoList(@RequestBody  AllName all) {
        return getDataTable(homePageService.needTodoList(all));
    }


    @ApiOperation("已办事项")
    @PostMapping("/finishedList")
    public AjaxResult finishedList(@RequestBody  AllName all) {
        return success(homePageService.finishedList(all));
    }

    @ApiOperation("办理进度")
    @PostMapping("/processSchedule")
    public TableDataInfo processSchedule(@RequestBody  AllName all) {
        return getDataTable(homePageService.processSchedule(all));
    }

    @ApiOperation("获取大模块下拉框")
    @GetMapping("/getLargeModules")
    public AjaxResult processSchedule() {
        return success(homePageService.getLargeModules());
    }


    @ApiOperation("办理统计")
    @GetMapping("/handleCount")
    public AjaxResult handleCount() {
        return success(homePageService.handleCount());
    }


    @ApiOperation("新增政策文件")
    @PostMapping("/addFileShare")
    public AjaxResult addFileShare(@RequestBody BizFileShare fileShare) {
        Boolean bl = fileSharedService.addFileShared(fileShare);
        return bl ? success() : error();
    }


    @ApiOperation("删除政策文件")
    @DeleteMapping("/delFileShare/{ids}")
    public AjaxResult delFileShare(@PathVariable String[] ids ) {
     fileSharedService.delFileShared(Arrays.asList(ids));
     return  success();
    }



    @ApiOperation("修改政策文件")
    @PostMapping("/updateFileShare")
    public AjaxResult updateFileShare(@RequestBody BizFileShare fileShare) {
        Boolean bl = fileSharedService.updateFileShared(fileShare);
        return bl ? success() : error();
    }

    @ApiOperation("查询文档共享列表")
    @PostMapping("/getFileShareList")
    public TableDataInfo getFileShareList(@RequestBody BizFileShare bizFileShare) {
        startPage();
        List<BizFileShare> list = fileSharedService.selectFileShared(bizFileShare);
        return  getDataTable(list);
    }

    @ApiOperation("项目金额统计")
    @GetMapping("/businessCount_fee")
    public AjaxResult businessCount_fee() {
        List<BusinessCount> businessCountFee = homePageService.businessCount_fee();
        return  success(businessCountFee);
    }

    @ApiOperation("项目数量统计")
    @GetMapping("/businessCount_projectNum")
    public AjaxResult businessCount_projectNum() {
        List<Map<String, Integer>> projectNum = homePageService.businessCount_projectNum();
        return  success(projectNum);
    }

    @ApiOperation("成果数量统计")
    @GetMapping("/businessCount_achievementNum")
    public AjaxResult businessCount_achievementNum() {
        List<Map<String, String>> achievementNum = homePageService.businessCount_achievementNum();
        return  success(achievementNum);
    }

    @ApiOperation("科研平台")
    @PostMapping("/getKypt")
    public TableDataInfo getKypt(@RequestBody ResearchUnit researchUnit) {
        startPage();
        researchUnit.setCheckStatus("2");
        String currentRoleKey = CurrentRoleUtils.getCurrentRoleKey();
        if ("biz_kyry".equals(currentRoleKey)) {
            Map<String, Object> map = researchUnit.getParams();
            map.put("curKyryPersonId", SecurityUtils.getLoginUser().getUser().getUserRealId());
        }

        List<ResearchUnit> list = researchUnitService.selectResearchUnitList(researchUnit);
        return getDataTable(list);
    }
}
